<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="批次号" prop="tiNo">
        <el-input
          v-model="queryParams.tiNo"
          placeholder="请输入提现批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="是否欠票" prop="isVote">
        <el-select
          clearable
          v-model="queryParams.isVote"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="否" value="1"> </el-option>
          <el-option label="是" value="2"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提现结果" prop="isVote">
        <el-select
          clearable
          v-model="queryParams.status"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="提现中" value="1"> </el-option>
          <el-option label="提现完成" value="2"> </el-option>
          <el-option label="提现失败" value="3"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:ti:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="tiList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="提现时间" align="center" prop="createTime" />
      <el-table-column label="提现批次号" align="center" prop="tiNo" />
      <el-table-column label="提现金额" align="center" prop="totalMoeny" />
      <el-table-column label="提现结果" align="center">
        <template slot-scope="scope">
          <el-tag>{{
            srmxStatus.withdrawalStatusTiList[scope.row.status]
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否欠票" align="center">
        <template slot-scope="scope">
          {{ scope.row.isVote == 1 ? "否" : "是" }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.status == 1"
            v-hasPermi="['system:ti:edit']"
            >审核</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="tidetails(scope.row.tiId)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="提现结果" prop="stsatus">
          <el-radio-group v-model="form.status">
            <el-radio label="2">通过</el-radio>
            <el-radio label="3">未通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否欠票" prop="isVote">
          <el-radio-group v-model="form.isVote">
            <el-radio label="1">否</el-radio>
            <el-radio label="2">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="发送短信" prop="isSend">
          <el-radio-group v-model="form.isSend">
            <el-radio label="1">发送</el-radio>
            <el-radio label="2">不发送</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="原因" prop="reason" v-if="form.status == 3">
          <el-input
            v-model="form.reason"
            type="textarea"
            placeholder="请输入内容"
            maxlength="300"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTi, getTi, delTi, addTi, updateTi } from "@/api/system/ti";

import { srmxStatus } from "@/utils/data.js";
export default {
  name: "Ti",
  data() {
    return {
      srmxStatus,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        skzhId: null,
        userId: null,
        tiNo: null,
        totalMoeny: null,
        status: null,
        isVote: null,
        reason: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        isSend: [{ required: true, message: "短信不能为空", trigger: "blur" }],
        reason: [{ required: true, message: "原因不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    tidetails(tiId) {
      this.$router.push({
        path: "/systemtd/details",
        query: { tiId },
      });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listTi(this.queryParams).then((response) => {
        this.tiList = response.rows;
        console.log(response.rows, "===");
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tiId: null,
        status: "2",
        isVote: "1",
        reason: null,
        isSend: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.tiId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form.tiId = row.tiId;
      this.open = true;
      this.title = "修改";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateTi(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tiIds = row.tiId || this.ids;
      this.$modal
        .confirm('是否确认删除编号为"' + tiIds + '"的数据项？')
        .then(function () {
          return delTi(tiIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/ti/export",
        {
          ...this.queryParams,
        },
        `ti_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
